//
//  IntelligenceViewController.m
//  ZhiShanUI
//
//  Created by 1 1 on 15/11/26.
//  Copyright © 2015年 Hiccup. All rights reserved.
//

#import "IntelligenceViewController.h"
#import "jiankangViewController.h"
#import "shoudongbangdingViewController.h"
#import "kongzhiViewController.h"
#import "KxMenu.h"

#define RGB(R, G, B, A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]
@interface IntelligenceViewController ()
{
    UIImageView * titltImgView;
    BOOL isFlag;
}

@end

@implementation IntelligenceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.navigationController.navigationBar.barTintColor = [[UIColor alloc] initWithRed:230/255.0 green:55/255.0 blue:55/255.0 alpha:1.0];
    
    
    UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 20, 20);
    [button setBackgroundImage:[UIImage imageNamed:@"smart_0000_盒子管理-1.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(messageBtnClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * rightItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.rightBarButtonItem = rightItem;
    
    
    UIView * titView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 120, 30)];
    
    UIButton* titleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    titleBtn.frame = CGRectMake(0, 0, 90, 30);
    [titleBtn setImage:[UIImage imageNamed:@"smart_0002_盒子选择.png"] forState:UIControlStateNormal];
    [titleBtn setTitle:@"mrjBOX" forState:UIControlStateNormal];
    [titleBtn addTarget:self action:@selector(titleClick) forControlEvents:UIControlEventTouchUpInside];
    [titView addSubview:titleBtn];
    
    titltImgView = [[UIImageView alloc] initWithFrame:CGRectMake(90, 0, 30, 30)];
    titltImgView.image = [UIImage imageNamed:@"smart_0001_下拉.png"];
    [titView addSubview:titltImgView];
    
    self.navigationItem.titleView = titView;
    
 
    
}







#pragma mark - 点击标题的方法
-(void)titleClick {
    isFlag = !isFlag;
    if (isFlag) {
        titltImgView.transform = CGAffineTransformMakeRotation(M_PI);
        NSArray *menuItems =@[ [KxMenuItem menuItem:@"扫描绑定"
                                              image:nil
                                             target:nil
                                             action:NULL],[KxMenuItem menuItem:@"手动绑定"
                                                                         image:nil
                                                                        target:nil
                                                                        action:NULL]];
        KxMenuItem *first = menuItems[0];
        first.foreColor = [UIColor whiteColor];
        first.alignment = NSTextAlignmentCenter;
        
        [KxMenu showMenuInView:self.view
                      fromRect:CGRectMake(self.view.bounds.size.width-200,17,50,50)
                     menuItems:menuItems];
    }else {
        titltImgView.transform =CGAffineTransformIdentity;
        [KxMenu dismissMenu];
    }
    
}

#pragma mark - 导航右侧按钮的方法
-(void)messageBtnClick {
    shoudongbangdingViewController *demoVC=[[shoudongbangdingViewController alloc]init];
    
//    [demoVC setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
//    [self presentModalViewController:demoVC animated:YES ];
    [self.navigationController pushViewController:demoVC animated:YES];
    
    
    
}

#pragma mark -
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)jiankang:(id)sender {
    
    
    jiankangViewController *demoVC=[[jiankangViewController alloc]init];
    
    [demoVC setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
    [self presentModalViewController:demoVC animated:YES ];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
